import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:word_app/app/modules/model/screen_adapter.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import '../controllers/my_home_controller.dart';

class MyHomeView extends GetView<MyHomeController> {
  const MyHomeView({super.key});

  Widget bannerWidget(MyHomeController controller) {
    return Container(
      padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
      child: AspectRatio(
          aspectRatio: 360 / 105,
          child: Swiper(
            itemBuilder: (context, index) {
              return ClipRRect(
                  borderRadius: BorderRadius.circular(10),
                  child: Image.asset("images/banner.png"));
            },
            itemCount: 2,
          )),
    );
  }

  Widget searchWidget(MyHomeController controller) {
    return Container(
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10), color: Colors.white),
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(left: 16, right: 16),
      height: 50,
      child: Row(
        children: [
          const Icon(Icons.search),
          const SizedBox(width: 10),
          Expanded(
            flex: 1,
            child: TextField(
              controller: controller.searchVc,
              decoration: const InputDecoration(
                  hintText: "请输入搜索内容",
                  enabledBorder: InputBorder.none,
                  focusedBorder: InputBorder.none),
            ),
          )
        ],
      ),
    );
  }

  Widget studyContentWidget() {
    return Container(
      margin: const EdgeInsets.all(16),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                padding: EdgeInsets.all(ScreenAdapterModel.width(10)),
                width: ScreenAdapterModel.width(72),
                height: ScreenAdapterModel.width(96),
                child: Image.asset("images/zkch.png"),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text(
                        "中考词汇",
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.black87,
                            fontSize: ScreenAdapterModel.fontSize(18)),
                      ),
                      const SizedBox(width: 10),
                      Text(
                        "修改 >",
                        style: TextStyle(
                            color: Colors.black38,
                            fontSize: ScreenAdapterModel.fontSize(11)),
                      )
                    ],
                  ),
                  Container(
                    height: 5,
                    width: ScreenAdapterModel.width(200),
                    margin: const EdgeInsets.only(right: 10, top: 5, bottom: 5),
                    color: Colors.black38,
                  ),
                  Text(
                    "0/23",
                    style: TextStyle(
                        color: Colors.black38,
                        fontSize: ScreenAdapterModel.fontSize(11)),
                  )
                ],
              )
            ],
          ),
          Container(
            height: 2,
            margin: const EdgeInsets.only(left: 10, right: 10, bottom: 20),
            color: Colors.black12,
          ),
          Padding(
            padding: EdgeInsets.only(left: 16),
            child: Text(
              "今日计划",
              style: TextStyle(
                  color: Colors.black87,
                  fontSize: ScreenAdapterModel.fontSize(15),
                  fontWeight: FontWeight.bold),
            ),
          ),
          Flex(
            direction: Axis.horizontal,
            children: [
              Expanded(
                flex: 1,
                child: Padding(
                  padding: const EdgeInsets.only(left: 20, top: 16, bottom: 16),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Text("已新学"),
                      const SizedBox(height: 15),
                      RichText(
                          text: TextSpan(children: [
                        TextSpan(
                            text: "0",
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: ScreenAdapterModel.fontSize(25),
                                color: Colors.black87)),
                        TextSpan(
                            text: "/100",
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: ScreenAdapterModel.fontSize(13),
                                color: Colors.black45))
                      ]))
                    ],
                  ),
                ),
              ),
              Expanded(
                  flex: 1,
                  child: Padding(
                      padding:
                          const EdgeInsets.only(left: 20, top: 16, bottom: 16),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          const Text("已掌握"),
                          const SizedBox(height: 15),
                          RichText(
                              text: TextSpan(children: [
                            TextSpan(
                                text: "0",
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontSize: ScreenAdapterModel.fontSize(25),
                                    color: Colors.black87)),
                            TextSpan(
                                text: "/100",
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontSize: ScreenAdapterModel.fontSize(13),
                                    color: Colors.black45))
                          ]))
                        ],
                      )))
            ],
          ),
          Flex(
            direction: Axis.horizontal,
            children: [
              Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      Get.toNamed("/study");
                    },
                    child: Container(
                      height: ScreenAdapterModel.width(57),
                      margin: const EdgeInsets.all(16),
                      decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 36, 79, 236),
                          borderRadius: BorderRadius.circular(5)),
                      child: const Center(
                        child: Text("学习",
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 18,
                                fontWeight: FontWeight.bold)),
                      ),
                    ),
                  )),
              Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      Get.toNamed("/study");
                    },
                    child: Container(
                      height: ScreenAdapterModel.width(57),
                      margin: const EdgeInsets.all(16),
                      decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 232, 235, 252),
                          borderRadius: BorderRadius.circular(5)),
                      child: const Center(
                        child: Text("复习",
                            style: TextStyle(
                                color: Color.fromARGB(255, 36, 79, 236),
                                fontSize: 18,
                                fontWeight: FontWeight.bold)),
                      ),
                    ),
                  ))
            ],
          )
        ],
      ),
    );
  }

  Widget bottomWidget() {
    return Container(
      height: ScreenAdapterModel.width(130),
      width: double.infinity,
      margin: const EdgeInsets.all(16),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "拍照翻译",
                style: TextStyle(
                    color: const Color.fromARGB(255, 68, 68, 68),
                    fontWeight: FontWeight.bold,
                    fontSize: ScreenAdapterModel.width(18)),
              ),
              Text(
                "一键拍翻生词",
                style: TextStyle(
                    color: const Color.fromARGB(255, 229, 229, 229),
                    fontWeight: FontWeight.bold,
                    fontSize: ScreenAdapterModel.width(18)),
              ),
              Image.asset(
                "images/gotophonefy.png",
                width: ScreenAdapterModel.width(28),
                height: ScreenAdapterModel.height(28),
              )
            ],
          ),
          Container(
            padding: const EdgeInsets.all(10),
            width: ScreenAdapterModel.width(118),
            height: ScreenAdapterModel.height(118),
            child: Image.asset("images/pzfylogo.png"),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    MyHomeController controller = Get.put(MyHomeController());
    return Scaffold(
      body: Container(
        padding: EdgeInsets.only(top: ScreenAdapterModel.getStatusBarHeight()),
        decoration: const BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
              Color.fromARGB(255, 222, 227, 255),
              Color.fromARGB(255, 237, 237, 237)
            ])),
        child: Column(
          children: [
            bannerWidget(controller),
            searchWidget(controller),
            studyContentWidget(),
            bottomWidget()
          ],
        ),
      ),
    );
  }
}
